package com.faryangsh.enumpack;

import java.util.EnumMap;
import java.util.Stack;

import static com.faryangsh.enumpack.AlarmPoints.*;

/**
 * 使用EnumMap实现命令模式
 * - 使用enum作为key
 * - enumMap内部是一个数组,查找效率高
 *
 * Created by 杨志远 on 2017/8/25
 * email faryangsh@163.com.
 */
public class EnumMapImplementCommand {
    private static EnumMap<AlarmPoints,Command> enumMap=new EnumMap<AlarmPoints, Command>(AlarmPoints.class);

    //往enumMap中放入命令(初始化命令map)
    static {
        enumMap.put(KITCHEN, new Command() {
            @Override
            public void action() {
                System.out.print("kitchen-----");
            }
        });
        enumMap.put(BATHROOM,()->{System.out.print("---BATHROOM--");});
    }

    public static void main(String[] args) {
        enumMap.get(KITCHEN).action();
    }
}

interface Command {
    void action();
}


